import { BasicColumn, FormSchema } from '/@/components/Table';

const statusOptions = [
  { label: '闲置', value: 1 },
  { label: '在用', value: 2 },
  { label: '维修中', value: 3 },
  { label: '报废', value: 4 },
  { label: '被领用', value: 5 },
];
const assetTypeOptions = [
  { label: '固定设备', value: 1 },
  { label: '租赁设备', value: 2 },
];
export const columns: BasicColumn[] = [
  {
    title: '设备名称',
    dataIndex: 'name',
  },
  {
    title: '设备编号',
    dataIndex: 'code',
  },
  {
    title: '设备型号',
    dataIndex: 'model',
  },
  {
    title: '资产类型',
    dataIndex: 'assetType',
    customRender({ text }) {
      const find = assetTypeOptions.find((opt) => opt.value === text);
      return find?.label || '未定义';
    },
  },
  {
    title: '设备实时状态',
    dataIndex: 'status',
    customRender({ text }) {
      const find = statusOptions.find((opt) => opt.value === text);
      return find?.label || '未知';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '设备名称',
    field: 'name',
    component: 'JInput',
  },
  {
    label: '资产类型',
    field: 'assetType',
    component: 'Select',
    componentProps: {
      options: assetTypeOptions,
    },
  },
  {
    label: '状态',
    field: 'status',
    component: 'Select',
    componentProps: {
      options: statusOptions,
    },
  },
];

export const formSchema: FormSchema[] = [
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '设备名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: '资产类型',
    field: 'assetType',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: assetTypeOptions,
    },
    required: true,
  },
  {
    label: '设备编号',
    field: 'code',
    component: 'Input',
  },
  {
    label: '设备型号',
    field: 'model',
    component: 'Input',
  },
  {
    label: '设备状态',
    field: 'status',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: statusOptions,
    },
    required: true,
  },
  {
    field: 'purchaseDate',
    label: '购置日期',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    colProps: { span: 15 },
  },
  {
    label: '购入价格(单价:元)',
    field: 'purchasePrice',
    component: 'Input',
    required: false,
  },
  {
    field: 'productionDate',
    label: '生产日期',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    colProps: { span: 15 },
  },
  {
    field: 'warrantyEnd',
    label: '保修截至日期',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    colProps: { span: 15 },
  },
  {
    label: '****存放地点',
    field: 'pidNames',
    component: 'Input',
    required: false,
  },
  {
    label: '供应商名称',
    field: 'supplier',
    component: 'Input',
    required: false,
  },
  {
    label: '功率',
    field: 'power',
    component: 'Input',
    required: false,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
    required: false,
  },
];
